{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\ul\b\f0\fs20 Source (http://guides.rubyonrails.org/getting_started.html)\ulnone\b0\par
\pard\qc\fs28 *****************************************************************************************************************************************************\par
**************************************************************Creating a New Rails Project*****************************************************\par
*****************************************************************************************************************************************************\fs20\par
\pard Prerequesties:\par
\tab The Ruby language\par
\tab A working installation of MySQL 5.0\par
\tab MySQL Administrator \par
\tab The RubyGems packaging system\par
\tab working internet connection\par
\par
Do some Preprocessing on commanad prompt by executing following command \par
\tab update gem [c:\\> gem update --system]\par
\tab Install Rails Framework [c:\\> gem install rails --include-dependencies]\par
\tab Install MySQL Driver for connectivity  [c:\\> gem install mysql]\par
\tab Install ruby debugger Debugger [c:\\> gem install ruby-debug]\par
\tab\par
\tab\par
\par
1 Installing Rails\par
\tab  gem install rails\par
\par
2 Creating the Blog Application\par
\tab Open a Connmad Prompt , navigate to a folder where you have rights to create files, and type:\par
\tab\par
\tab\tab > rails blog\par
\tab This will create a Rails application that uses a SQLite database for data storage. \par
\par
\tab If you prefer to use MySQL, run this command instead:\par
\tab\tab > rails blog -d mysql or\par
\tab\tab > rails blog -D mysql\par
\par
\tab And if you\rquote re using PostgreSQL for data storage, run this command:\par
\tab > rails blog -d postgresql\par
\par
\tab TIP. You can see all of the switches that the Rails application builder accepts by running rails -h.\par
\par
\tab After you create the blog application, switch to its folder to continue work directly in that application:\par
\tab\par
\tab\tab > cd blog\par
\tab In any case, Rails will create a folder in your working directory called blog.Most of the work in this tutorial will happen in the app/ folder,\par
\par
3 Configuring a Database\par
\tab Just about every Rails application will interact with a database. The database to use is specified in a configuration file, config/database.yml. The file contains sections for \tab\tab three different environments in which Rails can run by default:\par
\par
\tab The development environment is used on your development computer as you interact manually with the application\par
\tab The test environment is used to run automated tests\par
\tab The production environment is used when you deploy your application for the world to use.\par
\par
\tab Configuring a MySQL Database [Note: carefully observe the single space before the colone sign.]\par
\par
\tab If you choose to use MySQL, your config/database.yml will look a little different. Here\rquote s the development section:\par
\par
\tab\tab development:\par
\tab\tab adapter: mysql\par
\tab\tab encoding: utf8\par
\tab\tab database: blog_development\par
\tab\tab pool: 5\par
\tab\tab username: root\par
\tab\tab password: ibm\par
\tab\tab socket: /tmp/mysql.sock\par
\par
\tab If your development computer\rquote s MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username \tab\tab and password in the development section as appropriate.\par
\par
\tab\par
\par
4 Creating the Database\par
\tab Now that you have your database configured, it\rquote s time to have Rails create an empty database for you. You can do this by running a rake command from your project folder:\par
\par
\tab\tab > rake db:create\par
\tab Rake is a general-purpose command-runner that Rails uses for many things. You can see the list of available rake commands in your application by running rake -T.\par
\par
5 Creating A Home page\par
\tab To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal from your \tab\tab project folder\par
\par
\tab\tab > ruby script/generate controller home index\par
\tab\par
\tab Rails will create several files for you, including following \par
\tab\tab app/controlers/home_controller.rb -------------with the Index method in it because Index() is the default method of any controlar \par
\tab\tab app/views/home/index.html.erb.  -------------This is the template that will be used to display the results of the index action (method) in the home controller\par
\par
\tab\tab Open app/views/home/index.html.erb file in your text editor and edit it to contain a single line of code:\par
\tab\tab\tab <h1>Hello, Rails!</h1>\par
\par
6.Starting up the Web Server\par
\tab You actually have a functional Rails application already \endash  after running only two commands! To see it, you need to start a web server on your development machine. You can \tab\tab do this by running another command from your project folder\par
\par
\tab\tab > ruby script/server --debugger\par
\tab\tab the [--debugger] switch is optional, it will attached the debugger with the web server\par
\par
\tab This will fire up an instance of the WEBrick server To see your application in action, open a browser window and navigate to http://localhost:3000. You should see Rails\rquote  \tab\tab default information page:\par
\par
\tab To view the home page you just created, navigate to http://localhost:3000/home/index.\par
\par
7.Setting the Application Home Page\par
\tab You\rquote d probably like to replace the \ldblquote Welcome Aboard\rdblquote  page with your own application\rquote s home page. The first step to doing this is to :\par
\par
\tab Delete the default page from your application that is.\par
\tab\tab public/index.html\par
\par
\tab Set the default controller of your application by adding another following line to the routing file, above the default routes located at the bottom of the config\\routs.rb:\par
\par
\tab map.root :controller => "home"\par
\par
\tab  It means whenever the web server receives request for the URL http://localhost:3000 the default controller (home) should be called consequencely the default action (index) \tab\tab of that controller should be excecuted.\par
\par
\tab Restart the WEBrick web server\par
\tab Now if you navigate to http://localhost:3000 in your browser, you\rquote ll see the home/index view.\par
\par
8.Creating a Resource\par
\tab In the case of the blog application, you can start by generating a scaffolded Blogpost resource: this will represent a single blog posting. To do this, enter this command in \tab\tab your terminal:\par
\par
\tab\tab > ruby script/generate scaffold Blogpost name:string title:string content:text\par
\par
\tab Discription of above command:\par
\tab "script" is a directory where "generate" command is located,.\par
\tab "scaffold" is argument of "generate" commanad tells to generate all the needed resource fot the application to experence the blog posting. \par
\tab "Blogpost" (notice the first latter 'B' is in caps) is the name of name of table in MySQL and name of controller, Model, and layout file.\par
\tab "name:string title:string content:text" is a space separated list of \par
\tab\tab Column_name:DataType for the Blogpost table in MySQL and \par
\tab\tab Attributes_name:DataType for the BlogPost Model in Ruby.\par
\par
\tab While scaffolding will get you up and running quickly, the \ldblquote one size fits all\rdblquote  code that it generates is unlikely to be a perfect fit for your application. In most cases, you\rquote ll need to \tab customize the generated code.\par
\par
\tab The scaffold generator will build 14 files in your application, along with some folders, and edit one more. Here\rquote s a quick overview of what it creates:\par
\par
\tab File\tab\tab\tab\tab\tab Purpose\par
------------------------------------------------\tab\tab -----------------------------------------------------------\tab\par
\tab app/models/post.rb\tab\tab\tab\tab The Post model\par
\tab db/migrate/20090113124235_create_posts.rb\tab Migration to create the posts table in your database (your name will include a different timestamp)\par
\tab app/views/posts/index.html.erb\tab\tab\tab A view to display an index of all posts\par
\tab app/views/posts/show.html.erb\tab\tab\tab A view to display a single post\par
\tab app/views/posts/new.html.erb\tab\tab\tab A view to create a new post\par
\tab app/views/posts/edit.html.erb\tab\tab\tab A view to edit an existing post\par
\tab app/views/layouts/posts.html.erb\tab\tab A view to control the overall look and feel of the other posts views\par
\tab public/stylesheets/scaffold.css\tab\tab\tab Cascading style sheet to make the scaffolded views look better\par
\tab app/controllers/posts_controller.rb\tab\tab The Posts controller\par
\tab test/functional/posts_controller_test.rb\tab\tab Functional testing harness for the posts controller\par
\tab app/helpers/posts_helper.rb\tab\tab\tab Helper functions to be used from the posts views\par
\tab config/routes.rb\tab\tab\tab\tab Edited to include routing information for posts\par
\tab test/fixtures/posts.yml\tab\tab\tab Dummy posts for use in testing\par
\tab test/unit/post_test.rb\tab\tab\tab\tab Unit testing harness for the posts model\par
\tab test/unit/helpers/posts_helper_test.rb\tab\tab Unit testing harness for the posts helper\par
\par
9. Running a Migration or create Tables\par
\tab One of the products of the script/generate scaffold command is a database migration. Migrations are Ruby classes that are designed to make it simple to create and \tab modify database tables. Rails uses rake commands to run migrations, and it\rquote s possible to undo a migration after it\rquote s been applied to your database. Migration filenames \tab include a timestamp to ensure that they\rquote re processed in the order that they were created.\par
\par
\tab If you look in the db/migrate/20090113124235_create_posts.rb file (remember, yours will have a slightly different name), here\rquote s what you\rquote ll find:\par
\par
\tab class CreatePosts < ActiveRecord::Migration\par
  \tab\tab def self.up\par
    \tab\tab\tab create_table :posts do |t|\par
      \tab\tab\tab\tab t.string :name\par
     \tab\tab\tab\tab t.string :title\par
      \tab\tab\tab\tab t.text :content\par
\par
     \tab\tab\tab\tab  t.timestamps\par
    \tab\tab\tab end\par
  \tab\tab end\par
\par
  \tab\tab def self.down\par
    \tab\tab\tab drop_table :posts\par
  \tab\tab end\par
\tab end\par
\tab If you were to translate that into words, it says something like: when this migration is run, create a table named posts with two string columns (name and title) and a text \tab\tab\tab column (content), and generate timestamp fields to track record creation and updating. \par
\par
\tab At this point, you can use a rake command to run the migration from your project directory:\par
\par
\tab\tab > rake db:migrate\par
\tab Remember, you can\rquote t run migrations before running rake db:create to create your database, as we covered earlier.\par
\par
\tab Because you\rquote re working in the development environment by default, this command will apply to the database defined in the development section of your \tab\tab\tab\tab config/database.yml file.\par
\par
10. Working with BlogPosts in the Browser\par
\tab Now you\rquote re ready to start working with posts. To do that, navigate to http://localhost:3000 and then click the \ldblquote My Blog\rdblquote  link:\par
\par
\tab This is the result of Rails rendering the index view of your posts. There aren\rquote t currently any posts in the database, but if you click the New Post link you can create one. After \tab that, you\rquote ll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single script/generate scaffold \tab command.\par
\tab Congratulations, you\rquote re riding the rails! Now it\rquote s time to see how it all works.\par
11.\par
\par
\par
\tab\tab\tab\par
}
 